import React, { PureComponent, Fragment } from 'react';
import { Row, Col, Card, message } from 'antd';
import { SecondHeaderC, PrimaryC, PrimaryGhostC } from '../../../../comps';
import InstructionSend from './common/InstructionSend';
import BondLend from './common/index.js';
import fundTradeStyle from './fundTrade.less';
import './default.less';
import moment from 'moment';
import 'moment/locale/zh-cn';
import { connect } from 'dva';

@connect(({ buybackOrderbj, bondTrade, bookkeepingSettleM, loading, userM: user }) => ({
  buybackOrderbj,
  bondTrade,
  bookkeepingSettleM,
  loading: loading.models.buybackOrderbj,
  saveLoading: loading.effects['bondTrade/saveInstruction2'],
  user,
}))
export default class BondLending extends PureComponent {
  state = {};

  //页面初始函数
  componentDidMount = () => {};

  rehandleSearch = () => {
    const { that } = this.props;
    that.handleSearch();
    that.setState({
      modalVisible: false,
    });
  };

  rehandleSearch2 = () => {
    const { that } = this.props;
    that.setState({
      modalVisible: false,
    });
  };

  orderInstruction2 = () => {
    const {
      fundTrade,
      tradeInfo,
      buybackOrderbj: { dictMap },
      type,
      that,
      dispatch,
    } = this.props;

    this.setState({
      saveLoading: true,
    });

    //交收
    dispatch({
      type: 'bookkeepingSettleM/getTradeInstruction',
      payload: {
        id: tradeInfo.id,
      },
      callback: (res) => {
        that.setState({
          saveLoading: false,
        });
        if (res == 'success') {
          that.handleSearch();
          that.setState({
            modalVisible: false,
          });
        } else {
          message.error(res.message);
        }
      },
    });
  };

  //取消
  onCancel = () => {
    const { that } = this.props;

    that.setState({
      modalVisible: false,
    });
  };

  render() {
    const { type, tradeInfo, dispatch } = this.props;

    return (
      <div>
        <Row gutter={{ lg: 15 }}>
          <Col>
            <Card title='债券借贷指令 ' className={fundTradeStyle.tabsCard}>
              <div className={fundTradeStyle.back}>
                {type === 'add' ? <BondLend type='1' rehandleSearch={this.rehandleSearch} rehandleSearch2={this.rehandleSearch2} /> : null}

                {type === 'update' && tradeInfo.trade16 ? (
                  <BondLend type='2' editInitValue={tradeInfo} rehandleSearch={this.rehandleSearch} rehandleSearch2={this.rehandleSearch2} />
                ) : null}

                {type === 'jiaoshou' && tradeInfo.trade16 ? (
                  <div>
                    <div style={{ marginTop: '20px' }}>
                      <BondLend type='3' initValue={tradeInfo.trade16} />
                    </div>
                    <div style={{ marginTop: '10px', float: 'right' }}>
                      <PrimaryC onClick={this.orderInstruction2} title='交收确认' />
                      <PrimaryGhostC style={{ marginLeft: '15px' }} onClick={this.onCancel} title='取消' />
                    </div>
                  </div>
                ) : null}

                {type === 'view' && tradeInfo.trade16 ? (
                  <div>
                    <div style={{ marginTop: '20px' }}>
                      <BondLend type='4' initValue={tradeInfo.trade16} />
                    </div>
                  </div>
                ) : null}
              </div>
            </Card>
          </Col>
        </Row>
      </div>
    );
  }
}
